﻿using System.Text;
using System;

namespace JsonCodeGenerator
{
    internal static class CommonExtension
    {
        /// <summary>
        /// 首字母转大写
        /// </summary>
        public static string ToUppercase(this string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }

            return char.ToUpper(input[0]) + input.Substring(1);
        }

        /// <summary>
        /// 首字母转小写
        /// </summary>
        public static string ToLowercase(this string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }

            return char.ToLower(input[0]) + input.Substring(1);
        }

        /// <summary>
        /// 转换驼峰命名
        /// </summary>
        public static string ConvertToCamelCase(this string input)
        {
            var parts = input.Split('_', StringSplitOptions.RemoveEmptyEntries);
            var sb = new StringBuilder();
            foreach (var part in parts)
            {
                sb.Append(char.ToUpper(part[0]));
                sb.Append(part.Substring(1).ToLower());
            }
            return sb.ToString();
        }

    }
}
